package com.lyyzoo.log;

import com.lyyzoo.util.Strings;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Logs {
    public static final Logger logger = getLogger(Logs.class);

    private Logs() {
    }

    public static void trace(Object obj, String msg) {
        trace(obj, msg);
    }

    public static void trace(Object obj, String msg, Object... args) {
        if (isTraceEnabled(obj)) {
            logger(obj).trace(msg, args);
        }

    }

    public static void debug(Object obj, String msg) {
        debug(obj, msg);
    }

    public static void debug(Object obj, String msg, Throwable t) {
        logger(obj).debug(msg, t);
    }

    public static void debug(Object obj, String msg, Object... args) {
        if (isDebugEnabled(obj)) {
            logger(obj).debug(msg, args);
        }

    }

    public static void info(Object obj, String msg) {
        info(obj, msg);
    }

    public static void info(Object obj, Throwable t) {
        info(obj, (String)null, (Throwable)t);
    }

    public static void info(Object obj, String msg, Throwable t) {
        if (isInfoEnabled(obj)) {
            logger(obj).info(msg, t);
        }

    }

    public static void info(Object obj, String msg, Object... args) {
        if (isInfoEnabled(obj)) {
            logger(obj).info(msg, args);
        }

    }

    public static void warn(Object obj, String msg) {
        warn(obj, msg);
    }

    public static void warn(Object obj, Throwable t) {
        warn(obj, (String)null, (Throwable)t);
    }

    public static void warn(Object obj, String msg, Throwable t) {
        if (isWarnEnabled(obj)) {
            logger(obj).warn(msg, t);
        }

    }

    public static void warn(Object obj, String msg, Object... args) {
        if (isWarnEnabled(obj)) {
            logger(obj).warn(msg, args);
        }

    }

    public static void error(Object obj) {
        error(obj, (String)null, (Object[])(obj));
    }

    public static void error(Object obj, String msg) {
        error(obj, msg);
    }

    public static void error(Object obj, Throwable t) {
        error(obj, (String)null, (Throwable)t);
    }

    public static void error(Object obj, String msg, Throwable t) {
        if (isErrorEnabled(obj)) {
            logger(obj).error(msg, t);
        }

    }

    public static void error(Object obj, String msg, Object... args) {
        if (isErrorEnabled(obj)) {
            logger(obj).error(msg, args);
        }

    }

    public static boolean isTraceEnabled(Object obj) {
        return logger(obj).isTraceEnabled();
    }

    public static boolean isDebugEnabled(Object obj) {
        return logger(obj).isDebugEnabled();
    }

    public static boolean isInfoEnabled(Object obj) {
        return logger(obj).isInfoEnabled();
    }

    public static boolean isWarnEnabled(Object obj) {
        return logger(obj).isWarnEnabled();
    }

    public static boolean isErrorEnabled(Object obj) {
        return logger(obj).isErrorEnabled();
    }

    public static boolean isDebug() {
        return logger.isInfoEnabled() && (logger.isWarnEnabled() || logger.isErrorEnabled());
    }

    public static void msg(Object obj) {
        if (obj instanceof List) {
            List<?> objs = (ArrayList)obj;
            StringBuffer sb = new StringBuffer();

            for(int i = 0; i < objs.size(); ++i) {
                Object o = objs.get(i);
                sb.append(Strings.toString(o));
                if (i < objs.size() - 1) {
                    sb.append("\n");
                }
            }

            System.out.println(sb);
        } else {
            String msg;
            if (obj instanceof String) {
                msg = (String)obj;
                if (isDebug()) {
                    System.out.println(msg);
                } else {
                    info(Logs.class, (String)msg);
                }
            } else {
                msg = Strings.toString(obj, true);
                msg = Strings.removeStart(msg, "'");
                msg = Strings.removeEnd(msg, "'");
                msg(msg);
            }
        }

    }

    public static void msgs(Object... obj) {
        msg(Strings.toString(obj));
    }

    public static void msgr(Object obj) {
        printHr();
        msg(obj);
    }

    public static void printHr(String name) {
        if (isDebug()) {
            System.out.println("====================================================================================================================================================================================");
            if (name == null) {
                name = "DEBUG";
            }

            System.out.println(name);
            System.out.println("====================================================================================================================================================================================");
        }

    }

    public static void printHr() {
        printHr((String)null);
    }

    private static Logger logger(Object obj) {
        Logger logger;
        if (obj instanceof Class) {
            logger = LoggerFactory.getLogger((Class)obj);
        } else {
            logger = LoggerFactory.getLogger(obj.getClass());
        }

        return logger;
    }

    public static Logger getLogger(Object obj) {
        return logger(obj);
    }
}